<link rel="stylesheet" href="${resource(dir:'css',file:'cupertino/jquery-ui-1.8.custom.css')}" />
<g:javascript src="jquery/jquery-ui-1.8.custom.min.js"/>

<script language="javascript">
    $(document).ready(function() {       
        $("#course").change(function(){
            $("#teacher").html($("#"+$(this).val()).html())
        })

        $(".everyCourse").click(function(){
            
            $('#dialog-form').dialog( "option" , "courseID" , [$(this).attr("id")] ) 
            $('#dialog-form').dialog('open');
        })    
        $("#dialog-form").dialog({
			autoOpen: false,
			height: 300,
			width: 350,
			modal: true,
			buttons: {
				'确定': function() {
                    if($("#course").val() == "" || $("#course").val() == null || $("#teacher").val() == "" || $("#teacher").val() == null){
                        alert("请选择课程和教师")
                    }   
                    var courseID = $('#dialog-form').dialog( "option" , "courseID")
                    // 验证此老师在本时间是否已经有课了
                    $.post("/cloud/planAjax/validTeacherCourseTime", {time:new Date().getTime(),teacherID:$('#teacher').val(),planID:$("#"+courseID).attr("planID")}, function(data) {
                         if( data.success == false ){
                            $('#validName').html(data.message);
                            
                        }else{
                            $('#validName').html(data.message);
                            $("#"+courseID).html($("#course").val()+"<br>("+$("#teacher").find("option:selected").text()+")")
                            $("#courseAndTeacher").val($("#courseAndTeacher").val()
                            +$("#"+courseID).attr("planID")+","
                            +$("#teacher").val()+","+$("#course").val()+"|")
                            $("#dialog-form").dialog('close');
                            $('#validName').html("");
                            $("#course").val("")
                            $("#teacher").html("");
                            $("#teacher").val("");
                        }
                    }, 'json');
				},
				'取消':function() {
					$(this).dialog('close');
				}
			},
			close: function() {
				//allFields.val('').removeClass('ui-state-error');
			}
		});
    });
 
</script>